<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">考题管理</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>考题管理</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            问题：
            <input id="exam-questions-title" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            题型：
            <select id="exam-questions-type">
                <option value="">-请选择-</option>
            </select>&emsp;
            科目：
            <select id="exam-questions-subject">
                <option value="">-请选择-</option>
            </select>&emsp;
            阶段：
            <select id="exam-questions-stage">
                <option value="">-请选择-</option>
            </select>&emsp;
            <button id="exam-questions-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
            <button id="exam-questions-btn-add" class="layui-btn icon-btn">添加</button>
        </div>
    </div>
    <div class="layui-card-body" id="exam-questions-div">
        <table class="layui-table" id="exam-questions" lay-filter="exam-questions-filter"></table>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="exam-questions-table-bar" >
<!--    <a class="layui-btn layui-btn-primary  layui-btn-xs "  lay-event="question-look">查看</a>-->
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="question-edit">修改</a>
</script>


<script>
    layui.use(['index','form', 'table', 'util', 'config', 'admin','layer'], function () {
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var form = layui.form;

        //获取考题类型
        admin.req("api-exam/questionType/findAll?status=1",{},function (res) {
            var data=res.data;
            for (let i = 0; i < data.length; i++) {
                $("#exam-questions-type").append('<option value="'+data[i].typeid+'">'+data[i].tpname+'</option>')
            }
        },"get");
        //获取科目类型
        admin.req("api-exam/questionSubject/findAll?status=1",{},function (res) {
            var data=res.data;
            for (let i = 0; i < data.length; i++) {
                $("#exam-questions-subject").append('<option value="'+data[i].subjid+'">'+data[i].sjname+'</option>')
            }
        },"get");
        //获取考题阶段
        admin.req("api-exam/question/getStage",{},function (data) {
            for (let i = 0; i < data.length; i++) {
                $("#exam-questions-stage").append('<option value="'+data[i]+'">'+data[i]+'</option>')
            }
        },"get");
        form.render();
        // 渲染表格
        table.render({
            elem: '#exam-questions',
            url: config.base_server + 'api-exam/question/findAll',
            method: 'get',
            where: {
                access_token: config.getToken().access_token,
            },
            page: true,
            height:'full-350',
            cols: [[
                {type: 'numbers' },
                {field: 'qtitle', title: '问题'},
                {field: 'tpname',width: 100, title: '问题类型'},
                {field: 'sjname',width: 100, title: '科目类型'},
                {field: 'stage',width: 100, title: '阶段'},
                {field: 'cretim',width: 120, title: '创建时间'},
                {field: 'updtim', width: 120,title: '修改时间'},
                {field: 'status',width:100, title: '状态',
                    templet:function (data) {
                        if(data.status==1){
                            return '<span class="layui-badge layui-bg-gray">使用</span>';
                        }else {
                            return '<span class="layui-badge layui-bg-orange">禁用</span>';
                        }
                    }
                },
                {align: 'center', toolbar: '#exam-questions-table-bar', title: '操作', width: 250}
            ]],
            limit:10,
        });

        table.on('tool(exam-questions-filter)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'question-look') { // 查看详情
                questionLook(data)
            }
            if (layEvent === 'question-edit') { // 编辑
                questionEdit(data)
            }
        });
        //查看详情
        // var questionLook = function (data) {
        //     admin.putTempData('question_data', data);
        //     admin.popupCenter({
        //         title: '考题查询',
        //         area: ['75%','75%'],
        //         path: 'pages/exam/exam-questions-detail.html',
        //     });
        // };
        //修改
        var questionEdit = function (data) {
            admin.putTempData('question_data', data);
            admin.popupCenter({
                title: '修改考题',
                area: ['40%','75%'],
                path: 'pages/exam/exam-questions-edit.html',
                success:function(layero){
                    $(layero).children('.layui-layer-content').css('overflow-y', 'auto');
                },
                finish: function () {
                    table.reload('exam-questions');
                }
            });
        };
        //条件搜索
        $("#exam-questions-btn-search").click(function () {
            let qtitle = $("#exam-questions-title").val();
            let typeid = $("#exam-questions-type").val();
            let subjid = $("#exam-questions-subject").val();
            let stage = $("#exam-questions-stage").val();
            let param={qtitle: qtitle, typeid: typeid,subjid: subjid,stage:stage};
            table.reload('exam-questions', {where: param});
        });
        //添加
        $("#exam-questions-btn-add").click(function () {
            admin.popupCenter({
                title: '考题新增',
                area: ['40%','75%'],
                path: 'pages/exam/exam-questions-add.html',
                success:function(layero){
                    $(layero).children('.layui-layer-content').css('overflow-y', 'auto');
                },
                finish: function () {
                    table.reload('exam-questions');
                }
            });
        });
    });
</script>